


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.StringReader;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.NumberFormat;
 import java.util.List;
 import java.util.Locale;
 import java.util.ResourceBundle;
 
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JPanel;
import javax.swing.JRadioButton;
 import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
 
 import org.apache.xmlrpc.XmlRpcException;
 import org.apache.xmlrpc.client.XmlRpcClient;
 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
 //import org.scalpel.locodo.Odometry;
 
 //import org.opencv.core.Point;
import org.scalpel.common.ParseObjects;
//import org.xmlrpc.android.XMLRPCException;
 

   /**
    * 
    */

public class PreferenceFrame extends JFrame {

   private static final long serialVersionUID = 3026411583416241649L;
    /* Menu des langues */
   private JMenuBar fMenuBar = new JMenuBar();
   private JMenu fMenuLangue = new JMenu();
   private JCheckBoxMenuItem fMenuEnglish = new JCheckBoxMenuItem();
   
   private ResourceBundle fBundle;
   
   XmlRpcClientConfigImpl fConfig = new XmlRpcClientConfigImpl();
   XmlRpcClient fClient = new XmlRpcClient();
	
	// on modifie la signature du constructeur pour qu�on puisse change les
   // langues dynamiquement
	
   private JPanel fContentPane;
 
   private JButton fStartXmlRpcClient = new JButton();
   private JTextField fIPAddressText = new JTextField();
   private JLabel fDistancePLabel = new JLabel();
   private JLabel fDistanceILabel = new JLabel();
   private JLabel fDistanceDLabel = new JLabel();
   private JTextField fDistancePText = new JTextField();
   private JTextField fDistanceIText = new JTextField();
   private JTextField fDistanceDText = new JTextField();
   private JButton fApplyDistanceCoef = new JButton();
   private JLabel fAnglePLabel = new JLabel();
   private JLabel fAngleILabel = new JLabel();
   private JLabel fAngleDLabel = new JLabel();
   private JTextField fAnglePText = new JTextField();
   private JTextField fAngleIText = new JTextField();
   private JTextField fAngleDText = new JTextField();
   private JButton fApplyAngleCoef = new JButton();
   private JLabel fSpeedMotorPLabel = new JLabel();
   private JLabel fSpeedMotorILabel = new JLabel();
   private JLabel fSpeedMotorDLabel = new JLabel();
   private JTextField fSpeedMotorPText = new JTextField();
   private JTextField fSpeedMotorIText = new JTextField();
   private JTextField fSpeedMotorDText = new JTextField();
   private JButton fApplySpeedMotorCoef = new JButton();
   private JTextField fDisableAngleStaticSpeedText = new JTextField();
   private JCheckBox fApplyDisableAngle = new JCheckBox();
   private JTextField fDisableDistanceStaticSpeedText = new JTextField();
   private JCheckBox fApplyDisableDistance = new JCheckBox();
   private JLabel fXLabel = new JLabel();
   private JTextField fXText = new JTextField();
   private JLabel fYLabel = new JLabel();
   private JTextField fYText = new JTextField();
   private JLabel fALabel = new JLabel();
   private JTextField fAText = new JTextField();
   private JLabel fCurrentXLabel = new JLabel();
   private JTextField fCurrentXText = new JTextField();
   private JLabel fCurrentYLabel = new JLabel();
   private JTextField fCurrentYText = new JTextField();
   private JLabel fCurrentALabel = new JLabel();
   private JTextField fCurrentAText = new JTextField();
   private JButton fApplyMove = new JButton();
   
   private JTextField Android;;
   
   private JLabel enslaveL;
   private JLabel No_enslaveL;
   private JRadioButton enslave;
   private JRadioButton No_enslave;
   private JLabel enslave_Distancel; 
   private JLabel enslave_Anglel; 
   private JLabel enslave_Speedl; 
   private JRadioButton enslave_DistanceR; 
   private JRadioButton enslave_AngleR; 
   private JRadioButton enslave_SpeedR; 
   private JButton Change;
   private JLabel precisionl;
   private JButton epilson_dl;
   private JTextField epilson_d = new JTextField();
   private JButton epilson_al;
   private JTextField epilson_a = new JTextField();
   private JButton Refresh;
	
   
   
	public PreferenceFrame(Locale locale) { 
		
		Initialisation();	
		// on ajoute un objet de d�finition de localisation "locale"
	       fBundle = ResourceBundle.getBundle("Preference", locale);
	       
	       /* Agencement du menu */
	       fMenuLangue.add(fMenuEnglish);
	       fMenuBar.add(fMenuLangue);
	       setJMenuBar(fMenuBar);
	       
	       // Initialisation des propri�t�s
	       
	       InitText(locale);
	   	     
		
	}
	public void Initialisation()
	{
	       /*setDefaultCloseOperation(EXIT_ON_CLOSE);
	       setResizable(true);
	       setSize(293, 123);
	       setVisible(true);*/
	 		
		Quitter();
		CreerFenetre();
		Centrer();
		Ecouter();
	}

   //Pour centrer l'apparition de la fenetre global
	public void Centrer()
	{
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		int larg=(dim.width-getWidth())/2;
		int haut=(dim.height-getHeight())/2;
		setLocation(larg,haut);
	}
   
		public void Quitter() //d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
	{
		WindowListener l = new WindowAdapter() // classe anonyme qui herite de WindowAdapter
		{
			public void windowClosing(WindowEvent e)
			{
			System.exit(0);
			}
		};
			addWindowListener(l);
	}
    //First rectangle
	public void CompleterPanneau1(JPanel panel)
	{
	
		enslaveL = new JLabel("Enslave"); 
		No_enslaveL = new JLabel("No_enslave");
	    enslave = new JRadioButton("enslave",true); 
	    No_enslave = new JRadioButton("No_enslave");
//	(x,y,width,height) 
	    enslaveL.setBounds(30,30, 100, 20); 
	    enslave.setBounds(10,30,20,20); 
        No_enslaveL.setBounds(170, 30, 100, 20);
		No_enslave.setBounds(150,30,20 ,20);
		
		Change=new JButton("Change");
		Change.setEnabled(false);
		Change.setBounds(420, 30, 120, 20);
		panel.add(Change);

     fStartXmlRpcClient.setBounds(170, 60, 200, 20);
     fIPAddressText.setBounds(380,60,150 ,20);
     
		//Ajout des composants sur la fenetre
		  panel.add(fStartXmlRpcClient);
		  panel.add( fIPAddressText );
		  
		  panel.add(enslave);
		  panel.add(No_enslave);
		  panel.add(enslaveL);
		  panel.add(No_enslaveL);

		  
		  //a finir
		  //Utiliser le panneau 2 pour récuperer les valeurs de PID?
		    enslave_Distancel = new JLabel("Enslave_Distance") ; 
		    fDisableAngleStaticSpeedText = new JTextField("Valeur Speed Angle");
		    enslave_Anglel =new JLabel ("enslave_Angle") ; 
		    enslave_Speedl =new JLabel ("enslave_Speed") ;
		    enslave_DistanceR = new JRadioButton("enslave_DistanceR",false); 
		    enslave_AngleR = new JRadioButton("enslave_AngleR",false); 
		    enslave_SpeedR = new JRadioButton("enslave_SpeedR",false); 
		   
		    enslave_Distancel.setBounds(30,60,150 ,20);
		    enslave_DistanceR.setBounds(10, 60, 20, 20);
			enslave_Anglel.setBounds(30,90,150 ,20);
			enslave_AngleR.setBounds(10, 90, 20, 20);

		    fDisableAngleStaticSpeedText.setBounds(400, 90, 80, 20);	
		    fApplyDisableAngle.setBounds(250,90 , 150, 20);
		    fApplyDisableDistance.setBounds(250, 120, 150, 20);
			fDisableDistanceStaticSpeedText.setBounds(400, 120, 80, 20);
		    enslave_Speedl.setBounds(30,120,150 ,20);
			enslave_SpeedR.setBounds(10, 120, 20, 20);
			

			  panel.add(enslave_Distancel);
			  panel.add(enslave_DistanceR);
			  panel.add(enslave_Anglel);
			  panel.add(enslave_AngleR);
			  panel.add(enslave_Speedl);
			  panel.add(enslave_SpeedR);
			  panel.add(fDisableAngleStaticSpeedText);
			  panel.add(fDisableDistanceStaticSpeedText);
		   panel.add(fApplyDisableDistance);
		   panel.add(fApplyDisableAngle);
		   
   }
	//dissocier PID Angle & distance & vitesse
	public void CompleterPanneau2( JPanel panel)
	{
		//L'allocation now useless apres prise des variables...
		//PID pour la distance
		//fDistancePText=new JTextField();
		fDistancePText.setBackground(Color.yellow);
		fDistanceIText=new JTextField();
		fDistanceIText.setBackground(Color.red);
		fDistanceDText=new JTextField();
		fDistanceDText.setBackground(Color.red);
		

		fDistancePLabel=new JLabel("P (K)");
		fDistanceILabel=new JLabel("I (1/Ti)");
		fDistanceDLabel=new JLabel("D (Td)");
		fApplyDistanceCoef=new JButton("Apply"); 

		  //Dl.setVisible(false);
		
		//(x,y,width,height) 
		
		fDistancePText.setBounds(55,30,50,20);
		fDistancePLabel.setBounds(20,30,50,20);
		fDistanceIText.setBounds(160, 30, 50, 20);
		fDistanceILabel.setBounds(115,30,50,20);
		fDistanceDText.setBounds(265,30,50,20);
		fDistanceDLabel.setBounds(220,30,50,20);
		fApplyDistanceCoef.setBounds(340,30,200,20);


		
		 
		 panel.add(fDistancePLabel);
		 panel.add(fDistancePText);
		 panel.add(fDistanceILabel);
		 panel.add(fDistanceIText);
		 panel.add(fDistanceDLabel);
		 panel.add(fDistanceDText);
		 panel.add(fApplyDistanceCoef); 
		 
		 //PID pour l'angle
		 
		fAnglePText=new JTextField();
		fAnglePText.setBackground(Color.yellow);
		fAngleIText=new JTextField();
		fAngleIText.setBackground(Color.red);
		fAngleDText=new JTextField();
		fAngleDText.setBackground(Color.red);
		fApplyAngleCoef=new JButton("Apply"); 
		
		fAnglePLabel=new JLabel("P (K)");
		fAngleILabel=new JLabel("I (1/Ti)");
		fAngleDLabel=new JLabel("D (Td)");

		
			fAnglePText.setBounds(55,80,50,20);
			fAnglePLabel.setBounds(20,80,50,20);
			fAngleIText.setBounds(160,80, 50, 20);
			fAngleILabel.setBounds(115,80,50,20);
			fAngleDText.setBounds(265,80,50,20);
			fAngleDLabel.setBounds(220,80,50,20);
			fApplyAngleCoef.setBounds(340,80,200,20);
			
			 
		panel.add(fAnglePLabel);
		panel.add(fAnglePText);
		panel.add(fAngleILabel);
		panel.add(fAngleIText);
		panel.add(fAngleDLabel);
		panel.add(fAngleDText);
		panel.add(fApplyAngleCoef);
		
		 //PID pour la vitesse
		
		fSpeedMotorPText.setBackground(Color.yellow);
		
		fSpeedMotorIText.setBackground(Color.red);
		
		fSpeedMotorDText.setBackground(Color.red);
		fApplySpeedMotorCoef=new JButton("Apply"); 

		fSpeedMotorPLabel=new JLabel("P (K)");
		fSpeedMotorILabel=new JLabel("I (1/Ti)");
		fSpeedMotorDLabel=new JLabel("D (Td)");
		
		
		
		fSpeedMotorPText.setBounds(55,130,50,20);
		fSpeedMotorPLabel.setBounds(20,130,50,20);
		fSpeedMotorIText.setBounds(160, 130, 50, 20);
		fSpeedMotorILabel.setBounds(115,130,50,20);
		fSpeedMotorDText.setBounds(265,130,50,20);
		fSpeedMotorDLabel.setBounds(220,130,50,20);
		fApplySpeedMotorCoef.setBounds(340,130,200,20);

		panel.add(fSpeedMotorPLabel);
		panel.add(fSpeedMotorPText);
		panel.add(fSpeedMotorILabel);
		panel.add(fSpeedMotorIText);
		panel.add(fSpeedMotorDLabel);
		panel.add(fSpeedMotorDText);
		panel.add(fApplySpeedMotorCoef); 
		

		   fDistancePText.setVisible(false);
		   fDistanceIText.setVisible(false);
		   fDistanceDText.setVisible(false);
		   fDistancePLabel.setVisible(false);
		   fDistanceILabel.setVisible(false);
		   fDistanceDLabel.setVisible(false);
		   fAnglePText.setVisible(false);
		   fAngleIText.setVisible(false);
		   fAngleDText.setVisible(false);
		   fAnglePLabel.setVisible(false);
		   fAngleILabel.setVisible(false);
		   fAngleDLabel.setVisible(false);
		   fSpeedMotorPText.setVisible(false);
		   fSpeedMotorIText.setVisible(false);
		   fSpeedMotorDText.setVisible(false);
		   fSpeedMotorPLabel.setVisible(false);
		   fSpeedMotorILabel.setVisible(false);
		   fSpeedMotorDLabel.setVisible(false);
		   fApplySpeedMotorCoef.setVisible(false);
		   fApplyAngleCoef.setVisible(false);
		   fApplyDistanceCoef.setVisible(false);
		   
	}
	//Rajout info angle par rapport à un axe?
	public void CompleterPanneau3( JPanel panel)
	
	{
		fXLabel=new JLabel("-Distance X- "); //origine a definir apres la creation de la nouvelle map
		fXLabel.setBounds(10, 30, 100, 20);
		panel.add(fXLabel);
		
		
		fXText.setBounds(110,30,40,20);
		panel.add(fXText);
		
		fYLabel=new JLabel("-Distance Y- ");
		fYLabel.setBounds(190,30 , 100, 20);
		panel.add(fYLabel);
		
		fYText.setBounds(290,30,40,20);
		panel.add(fYText);
		
		
		fALabel = new JLabel("-Or Angle A-");
		fALabel.setBounds(360,30 , 150, 20);
		panel.add(fALabel);
		
		fAText.setBounds(480,30,40,20);
		panel.add(fAText);
		
		fApplyMove.setBounds(175, 60, 200, 20);
		panel.add(fApplyMove);

		
	}
	public void CompleterPanneau4( JPanel panel)
	{

	fCurrentXLabel.setBounds(20, 15, 200, 30);
	panel.add(fCurrentXLabel);

		fCurrentXText.setBounds(150,20,50,20);
		panel.add(fCurrentXText);
		
    //fCurrentYLabel = new JLabel("y (m)");
	fCurrentYLabel.setBounds(20, 45, 200, 30);
	panel.add(fCurrentYLabel);

		fCurrentYText.setBounds(150,50,50,20);
		panel.add(fCurrentYText);
		

	fCurrentALabel.setBounds(20, 75, 200, 30);
	panel.add(fCurrentALabel);

		fCurrentAText.setBounds(150,80,50,20);
		panel.add(fCurrentAText);

	 
	precisionl=new JLabel("For change precision");
	precisionl.setBounds(300, 10, 150, 30);
	panel.add(precisionl);
	 
	epilson_dl=new JButton("Modify Epilson d");
	epilson_dl.setBounds(300, 65, 150, 20);
	panel.add(epilson_dl);
	
	epilson_d.setBounds(350, 40, 50, 20);
	panel.add(epilson_d);
		
	epilson_al=new JButton("Modify Epilson a");
	epilson_al.setBounds(300, 115, 150, 20);
	panel.add(epilson_al);
	
	epilson_a.setBounds(350, 90, 50, 20);
	panel.add(epilson_a);
	
	Refresh=new JButton("Refresh");
	Refresh.setBounds(30, 120, 150, 20);
	panel.add(Refresh);
		
	}
	
	public void CompleterPanneau5( JPanel panel)
	{
		Android = new JTextField("Android Application which looking for it");
		Android.setBounds(30, 30, 300, 20);
		panel.add(Android);

	}
	
	public void CreerFenetre()
	{
		 setSize(600,800); //taille global
		 JPanel panneau_general = new JPanel();
		 panneau_general.setLayout(null);
		 
		 JPanel panneau1 = new JPanel();
		 panneau1.setLayout(null);
		 panneau1.setBorder(new TitledBorder("Selection Enslave or not"));
		 panneau1.setBounds(10, 10, 550, 160);
		 CompleterPanneau1(panneau1);
		 panneau_general.add(panneau1);
		 setContentPane(panneau_general);

		 JPanel panneau2 = new JPanel();
		 panneau2.setLayout(null);
		 panneau2.setBorder(new TitledBorder("PID Control" ));
		 panneau2.setBounds(10, 180, 550, 160);
		 CompleterPanneau2(panneau2);
		 panneau_general.add(panneau2); 

		
		 JPanel panneau3 = new JPanel();
		 panneau3.setLayout(null);
		 panneau3.setBorder(new TitledBorder("Choice of Target Position"));
		 panneau3.setBounds(10, 350, 550, 100);
		 CompleterPanneau3(panneau3);
		 panneau_general.add(panneau3);
		 
		 JPanel panneau4 = new JPanel();
		 panneau4.setLayout(null);
		 panneau4.setBorder(new TitledBorder("Current Position & Precisions"));
		 panneau4.setBounds(10, 460, 550, 160);
		 CompleterPanneau4(panneau4);
		 panneau_general.add(panneau4);
	
		 JPanel panneau5 = new JPanel();
		 panneau5.setLayout(null);
		 panneau5.setBorder(new TitledBorder("Current Parameters & Test I2C"));
		 panneau5.setBounds(10, 630, 550, 120);
		 CompleterPanneau5(panneau5);
		 panneau_general.add(panneau5);
	
	}
	
	public void Ecouter()
	{

		enslave.addActionListener(new ActionListener(){
	         public void actionPerformed(ActionEvent e){ Onenslave();}});
		No_enslave.addActionListener(new ActionListener(){
	         public void actionPerformed(ActionEvent e){ Offenslave();}});
		Change.addActionListener(new ActionListener(){
	         public void actionPerformed(ActionEvent e){ Change();}});
		enslave_DistanceR.addActionListener(new ActionListener(){
	         public void actionPerformed(ActionEvent e){ enslave_DistanceR();}});
		enslave_AngleR.addActionListener(new ActionListener(){
	         public void actionPerformed(ActionEvent e){ enslave_AngleR();}});
		enslave_SpeedR.addActionListener(new ActionListener(){
	         public void actionPerformed(ActionEvent e){ enslave_SpeedR();}});
		
		  /**public Object[] getPosition(){
			    KeyPoint p = fLocoEngine.getPosition();
			    Object [] res = new Object[3];
			    res[0] = p.x;
			    res[1] = p.y;
			    res[2] = p.a;
			    return res;
			  }*/
		/**	public Object callEx(String method, Object[] params) throws XMLRPCException {
		try {
			// prepare POST body
			String body = methodCall(method, params);*/
		
	       Refresh.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){Refresh();

    Object[] toto = new Object[3];
    try {
      fClient.execute( "world.modloco.getPosition" , toto); //pb get
     // fCurrentXText.setText(toto.x);
      //fCurrentXText.setText(toto.x);
      //fCurrentXText.setText(toto.x);

    } catch (XmlRpcException ex) {
      // TODO Auto generated catch block
      ex.printStackTrace();
    }
	  
	  //Recuperer Pos.x /pos .y / actuel

  }
});
	       epilson_dl.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
	  Object[] params = new Object[]{  new Double( Double.parseDouble(fCurrentXText.getText()) ),
      new Double( Double.parseDouble(fCurrentYText.getText()) ),
      new Double( Double.parseDouble(fCurrentAText.getText()) )
    };
try {
fClient.execute( "world.modloco.getCurrentPosition" , params);
} catch (XmlRpcException ex) {
// TODO Auto generated catch block
ex.printStackTrace();
}

  }
});
		
		       fApplyMove.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){fApplyMove();
           Object[] params = new Object[]{  new Double( Double.parseDouble(fXText.getText()) ),
                                           new Double( Double.parseDouble(fYText.getText()) ),
                                           new Double( Double.parseDouble(fAText.getText()) )
                                         };
           try {
             fClient.execute( "world.modloco.setTarget", params);
           } catch (XmlRpcException ex) {
             // TODO Auto generated catch block
             ex.printStackTrace();
           }
         }
       });
		fStartXmlRpcClient.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
           
           try {
             fConfig.setServerURL(new URL("http://"+fIPAddressText.getText()+":49157/"));
           } catch (MalformedURLException e1) {
             // TODO Auto generated catch block
             e1.printStackTrace();
           } // First Prime Number after in the "Dynamic, private or ephemeral" ports range: 49152�65535
           
           fClient.setConfig(fConfig);
           
           ParseObjects p = new ParseObjects("world.inspector", fClient);
           String[] s = p.getHHObjectList();
         }
       });
 
       fApplyDistanceCoef.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
           
           Object[] params = new Object[]{  new Double( Double.parseDouble(fDistancePText.getText()) ),
                                           new Double( Double.parseDouble(fDistanceIText.getText()) ),
                                           new Double( Double.parseDouble(fDistanceDText.getText()) )
                                           };
           try {
             fClient.execute( "world.modloco.setDistancePid", params);
           } catch (XmlRpcException ex) {
             // TODO Auto generated catch block
             ex.printStackTrace();
           }
         }
       });
       
       
       
       fApplyAngleCoef.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
           Object[] params = new Object[]{  new Double( Double.parseDouble(fAnglePText.getText()) ),
                                           new Double( Double.parseDouble(fAngleIText.getText()) ),
                                           new Double( Double.parseDouble(fAngleDText.getText()) )
                                         };
           try {
             fClient.execute( "world.modloco.setAnglePid", params);
           } catch (XmlRpcException ex) {
             // TODO Auto generated catch block
             ex.printStackTrace();
           }
         }
       });
 
       fApplySpeedMotorCoef.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
           Object[] params = new Object[]{  new Double( Double.parseDouble(fSpeedMotorPText.getText()) ),
                                           new Double( Double.parseDouble(fSpeedMotorIText.getText()) ),
                                           new Double( Double.parseDouble(fSpeedMotorDText.getText()) )
                                         };
           try {
             fClient.execute( "world.modloco.setSpeedMotorPid", params);
           } catch (XmlRpcException ex) {
             // TODO Auto generated catch block
             ex.printStackTrace();
           }
         }
       });
 
       fDisableAngleStaticSpeedText.addActionListener( new ActionListener(){
         public void actionPerformed(ActionEvent e){
           if( !fApplyDisableAngle.isSelected() ) return;
           Object[] params = new Object[]{  new Boolean( fApplyDisableAngle.isSelected() ),
                                           new Double( Double.parseDouble(fDisableAngleStaticSpeedText.getText()) )
                                         };
           try {
             fClient.execute( "world.modloco.disableAngleControl", params);
           } catch (XmlRpcException ex) {
             // TODO Auto generated catch block
             ex.printStackTrace();
           }
         }
       });
 
       fApplyDisableAngle.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
           Object[] params = new Object[]{  new Boolean( fApplyDisableAngle.isSelected() ),
                                           new Double( Double.parseDouble(fDisableAngleStaticSpeedText.getText()) )
                                         };
           try {
             fClient.execute( "world.modloco.disableAngleControl", params);
           } catch (XmlRpcException ex) {
             // TODO Auto generated catch block
             ex.printStackTrace();
           }
         }
       });

       fDisableDistanceStaticSpeedText.addActionListener( new ActionListener(){
         public void actionPerformed(ActionEvent e){
           if( !fApplyDisableDistance.isSelected() ) return;
           Object[] params = new Object[]{  new Boolean( fApplyDisableDistance.isSelected() ),
                                           new Double( Double.parseDouble(fDisableDistanceStaticSpeedText.getText()) )
                                         };
           try {
             fClient.execute( "world.modloco.disableDistanceControl", params);
           } catch (XmlRpcException ex) {
             // TODO Auto generated catch block
             ex.printStackTrace();
           }
         }
       });
       
       fApplyDisableDistance.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
           Object[] params = new Object[]{  new Boolean( fApplyDisableDistance.isSelected() ),
                                           new Double( Double.parseDouble(fDisableDistanceStaticSpeedText.getText()) )
                                         };
           try {
             fClient.execute( "world.modloco.disableDistanceControl", params);
           } catch (XmlRpcException ex) {
        	   
             // TODO Auto generated catch block
             ex.printStackTrace();
           }
         }
       });
 

       fMenuEnglish.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
               Locale locale = new Locale("en", "US");
               fBundle = ResourceBundle.getBundle("Preference", locale);
               InitText(locale);
           }
       });
       
	}
	
	/*public  void actionPerformed(ActionEvent e) 
	{
		Object  source=e.getSource(); 
    if (source==enslave) Onenslave();
    if (source==No_enslave)Offenslave();
    if (source==Lancer)Lancer();
    if (source==Change)Change();
    if (source==enslave_DistanceR)enslave_DistanceR(); 
    //if (source!=enslave_DistanceR)enslave_DistanceR();
    if (source==enslave_AngleR)enslave_AngleR(); 
    if (source==enslave_SpeedR)enslave_SpeedR(); 
	}*/
	public void enslave_DistanceR()
	{
   fDistancePText.setVisible(true);
   fDistanceIText.setVisible(true);
   fDistanceDText.setVisible(true);
   fDistancePLabel.setVisible(true);
   fDistanceILabel.setVisible(true);
   fDistanceDLabel.setVisible(true);
   fApplyDistanceCoef.setVisible(true);

	}
	public void enslave_AngleR()
	{
	
   fAnglePText.setVisible(true);
   fAngleIText.setVisible(true);
   fAngleDText.setVisible(true);
   fAnglePLabel.setVisible(true);
   fAngleILabel.setVisible(true);
   fAngleDLabel.setVisible(true);
   fApplyAngleCoef.setVisible(true);
   
	}
	public void enslave_SpeedR()
	{
   fSpeedMotorPText.setVisible(true);
   fSpeedMotorIText.setVisible(true);
   fSpeedMotorDText.setVisible(true);
   fSpeedMotorPLabel.setVisible(true);
   fSpeedMotorILabel.setVisible(true);
   fSpeedMotorDLabel.setVisible(true);
   fApplySpeedMotorCoef.setVisible(true);

	}
	public void Onenslave()
	{
		No_enslave.setEnabled(false); 
		
	}
	public void Offenslave()
	{
		enslave.setEnabled(false);
		enslave_DistanceR.setEnabled(false); 
		enslave_AngleR.setEnabled(false); 
		enslave_SpeedR.setEnabled(false); 

	}
	public void fApplyMove()
	{
      fDistancePText.setEnabled(false);
      fDistanceIText.setEnabled(false);
      fDistanceDText.setEnabled(false);
      fAnglePText.setEnabled(false);
      fAngleIText.setEnabled(false);
      fAngleDText.setEnabled(false);
      fSpeedMotorDText.setEnabled(false);
      fSpeedMotorIText.setEnabled(false);
      fSpeedMotorPText.setEnabled(false);
      Change.setEnabled(true);
      fApplyMove.setEnabled(false);
      

	}
	public void Change()
	{
		fDistancePText.setEnabled(true);
		fDistanceIText.setEnabled(true);
		fDistanceDText.setEnabled(true);
	      fAnglePText.setEnabled(true);
	      fAngleIText.setEnabled(true);
	      fAngleDText.setEnabled(true);
	      fSpeedMotorDText.setEnabled(true);
	      fSpeedMotorIText.setEnabled(true);
	      fSpeedMotorPText.setEnabled(true);
		fApplyMove.setEnabled(true);
	      Change.setEnabled(false);
	}
public void Refresh()
{
	
}
 
       /*fContentPane = (JPanel) this.getContentPane();
       
       JPanel controlsForm = new JPanel();
 
       GridBagLayout layout = new GridBagLayout(); 
       GridBagConstraints layoutConstraints = new GridBagConstraints(); 
       
       controlsForm.setLayout(layout);
       
       int gridId = 0;
       layoutConstraints.fill = GridBagConstraints.HORIZONTAL;
       layoutConstraints.anchor = GridBagConstraints.NORTHWEST;
       
       layoutConstraints.gridy = 0;
       layoutConstraints.gridx = gridId;
       layout.setConstraints(fStartXmlRpcClient, layoutConstraints);
       controlsForm.add(fStartXmlRpcClient);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fIPAddressText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fDistancePLabel, layoutConstraints);
 
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fDistancePText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fDistanceILabel, layoutConstraints);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fDistanceIText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fDistanceDLabel, layoutConstraints);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fDistanceDText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId++;
       layoutConstraints.gridwidth = 2;
       controlsForm.add(fApplyDistanceCoef, layoutConstraints);
       
       //////////
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fAnglePLabel, layoutConstraints);
 
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fAnglePText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fAngleILabel, layoutConstraints);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fAngleIText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fAngleDLabel, layoutConstraints);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fAngleDText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId++;
       layoutConstraints.gridwidth = 2;
       controlsForm.add(fApplyAngleCoef, layoutConstraints);
       
       //////////
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fSpeedMotorPLabel, layoutConstraints);
 
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fSpeedMotorPText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fSpeedMotorILabel, layoutConstraints);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fSpeedMotorIText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fSpeedMotorDLabel, layoutConstraints);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fSpeedMotorDText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId++;
       layoutConstraints.gridwidth = 2;
       controlsForm.add(fApplySpeedMotorCoef, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       layoutConstraints.gridwidth = 1;
       controlsForm.add(fApplyDisableAngle, layoutConstraints);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       layoutConstraints.gridwidth = 1;
       controlsForm.add(fDisableAngleStaticSpeedText, layoutConstraints);
 
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       layoutConstraints.gridwidth = 1;
       controlsForm.add(fApplyDisableDistance, layoutConstraints);
       
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       layoutConstraints.gridwidth = 1;
       controlsForm.add(fDisableDistanceStaticSpeedText, layoutConstraints);
 
       
     ///
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fGotoXLabel, layoutConstraints);
 
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fGotoXText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fGotoYLabel, layoutConstraints);
 
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fGotoYText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId;
       controlsForm.add(fGotoALabel, layoutConstraints);
 
       layoutConstraints.gridx = 1;
       layoutConstraints.gridy = gridId++;
       controlsForm.add(fGotoAText, layoutConstraints);
       
       layoutConstraints.gridx = 0;
       layoutConstraints.gridy = gridId++;
       layoutConstraints.gridwidth = 2;
       controlsForm.add(fApplyMove, layoutConstraints);
       
       fContentPane.add(BorderLayout.WEST, controlsForm);
       
       final DiagramPanel diagramPanel = new DiagramPanel(fBundle);
       fContentPane.add(diagramPanel, null);
       */
       
   // M�thode pour initialiser les propri�t�s (l'ensemble des noms en mêmes temps)
   private void InitText(Locale locale) {
 
       // on initialise les variable d�internationalisation
       setTitle(fBundle.getString("PTitle"));
       
       fStartXmlRpcClient.setText(fBundle.getString("PStartXmlRpcClient"));
       fIPAddressText.setText("192.168.43.1");
       //A voir si espace suffisant sue le panel--change sur Preference_en_US.
       //fDistancePLabel.setText(fBundle.getString("PDistanceP")); 
       //fDistanceILabel.setText(fBundle.getString("PDistanceI"));
       //fDistanceDLabel.setText(fBundle.getString("PDistanceD"));
       fApplyDistanceCoef.setText(fBundle.getString("PApplyDistancePID"));
       //fAnglePLabel.setText(fBundle.getString("PAngleP"));
       //fAngleILabel.setText(fBundle.getString("PAngleI"));
       //fAngleDLabel.setText(fBundle.getString("PAngleD"));
       fApplyAngleCoef.setText(fBundle.getString("PApplyAnglePID"));
       //fSpeedMotorPLabel.setText(fBundle.getString("PSpeedMotorP"));
       //fSpeedMotorILabel.setText(fBundle.getString("PSpeedMotorI"));
       //fSpeedMotorDLabel.setText(fBundle.getString("PSpeedMotorD"));
       fApplySpeedMotorCoef.setText(fBundle.getString("PApplySpeedMotorPID"));
       fCurrentXLabel.setText(fBundle.getString("PCurrentX"));
       fCurrentYLabel.setText(fBundle.getString("PCurrentY"));
       fCurrentALabel.setText(fBundle.getString("PCurrentA"));
       fApplyMove.setText(fBundle.getString("PApplyMove"));
       
       // Menu
       fMenuLangue.setText("Langue");//Messages.getString("PLangue"));
       fMenuEnglish.setText("Anglais");//Messages.getString("PAnglais"));
 
       // on ajout des �l�ments relatives � la langues et le pays pour
       // mieux voir le r�sultat.
       fDistancePText.setText(Double.toString(1.0));
       fDistanceIText.setText(Double.toString(0.0));
       fDistanceDText.setText(Double.toString(0.0));
       fAnglePText.setText(Double.toString(1.0));
       fAngleIText.setText(Double.toString(0.0));
       fAngleDText.setText(Double.toString(0.0));
       fSpeedMotorPText.setText(Double.toString(1.0));
       fSpeedMotorIText.setText(Double.toString(0.0));
       fSpeedMotorDText.setText(Double.toString(0.0));
       fCurrentXText.setText(Double.toString(0.0));
       fCurrentYText.setText(Double.toString(0.0));
       fCurrentAText.setText(Double.toString(0.0));
       fXText.setText(Double.toString(0.0));
       fYText.setText(Double.toString(0.0));
       fAText.setText(Double.toString(0.0));
       fDisableDistanceStaticSpeedText.setText(Double.toString(0.0));
       fDisableAngleStaticSpeedText.setText(Double.toString(0.0));
       fApplyDisableAngle.setSelected(false);
       fApplyDisableAngle.setText(fBundle.getString("DisableAngle"));
       fApplyDisableDistance.setSelected(false);
       fApplyDisableDistance.setText(fBundle.getString("DisableDistance"));
       epilson_d.setText(Double.toString(9.9));
       epilson_a.setText(Double.toString(9.9));

   }
   }
   
   
